<template>
  <div class="sfc-pay-container">
    <div class="matchs-detail">
      <div class="match-item" :key="i" v-for="(match, i) in matchList">
        <div class="match-content">
          <div class="match-score">
            {{match.home_team_name}}（主）
            <span>VS</span>
            {{match.guest_team_name}}（客）
          </div>
          <div class="match-select" @click="selectMatch(match)">点击展开比分投注区</div>
        </div>
        <div class="match-info">
          <x-icon type="ios-minus-outline" size="20" @click="delMatch(i)"></x-icon>
        </div>
      </div>
    </div>
    <confirm
      v-if="showSelectModal"
      v-model="showSelectModal"
      @on-cancel="showSelectModal=false"
      @on-confirm="confirmSelectModal"
      class="match-modal-sfc-s-pay"
    >
      <div class="title">
        {{selectedMatch.home_team_name}}
        <img
          class="logo"
          src="../../../assets/imgs/live/zhu.png"
          alt
        >
        <span>VS</span>
        {{selectedMatch.guest_team_name}}
        <img
          class="logo"
          src="../../../assets/imgs/live/ke.png"
          alt
        >
      </div>
      <div class="detail">
        <div class="s">
          <div class="left">主胜</div>
          <div class="right">
            <div
              :key="mindex"
              v-for="(mitem, mindex) in selectedMatch.zs"
              :class="{active: (copybf.zs || {})[mindex] ? 'active' : '', item: true}"
              @click="onMatchSelect('zs', mindex, mitem[2])"
            >
              <div class="jq">{{mitem[1]}}</div>
              <div class="score">{{mitem[2]}}</div>
            </div>
          </div>
        </div>
        <div class="f">
          <div class="left">客胜</div>
          <div class="right">
            <div
              :key="mindex"
              v-for="(mitem, mindex) in selectedMatch.ks"
              :class="{active: (copybf.ks || {})[mindex] ? 'active' : '', item: true}"
              @click="onMatchSelect('ks', mindex, mitem[2])"
            >
              <div class="jq">{{mitem[1]}}</div>
              <div class="score">{{mitem[2]}}</div>
            </div>
          </div>
        </div>
      </div>
    </confirm>
  </div>
</template>
<script>
import { Confirm } from "vux";
export default {
  components: {
    Confirm
  },
  props: {
    matchList: {
      type: Array
    },
    selectedMatchs: {
      type: Object
    }
  },
  data() {
    return {
      showSelectModal: false,
      copybf: {},
      selectedMatch: {}
    };
  },
  methods: {
    showDetail(item) {
      item.showDetail = !item.showDetail;
      this.$forceUpdate();
    },
    selectMatch(match) {
      const { nm_matches_id, issue_num } = match;
      const selectedbf = {};
      if (
        this.selectedMatchs[nm_matches_id] &&
        this.selectedMatchs[nm_matches_id][issue_num]
      ) {
        selectedbf.zs = this.selectedMatchs[nm_matches_id][issue_num].zs || {};
        selectedbf.ks = this.selectedMatchs[nm_matches_id][issue_num].ks || {};
      }
      this.copybf = { ...selectedbf };
      this.selectedMatch = match;
      this.showSelectModal = true;
    },
    confirmSelectModal() {
      const data = { ...this.copybf };
      const { nm_matches_id, issue_num } = this.selectedMatch;
      this.$emit("selectAllBatchMatch", {
        nm_matches_id,
        issue_num,
        data
      });
    },
    onMatchSelect(type, index, value) {
      if (!this.copybf[type]) {
        const typeObj = {
          [index]: value
        };
        this.$set(this.copybf, type, typeObj);
      } else {
        if (this.copybf[type][index]) {
          this.$delete(this.copybf[type], index);
        } else {
          this.$set(this.copybf[type], index, value);
        }
      }
    },
    delMatch(index) {
      const { nm_matches_id } = this.matchList[index];
      this.$delete(this.selectedMatchs, nm_matches_id);
      this.matchList.splice(index, 1);
      // this.setLocalstorage();
    }
  }
};
</script>
<style lang="less">
.sfc-pay-container {
  font-size: 0.24rem;
  .matchs-detail {
    background: #fff3f4;
    .match-item {
      display: flex;
      border-bottom: 1px solid #d2d2d2;
      align-items: center;
      .match-info {
        width: 1.2rem;
        padding: 0.2rem;
        color: #202020;
        font-size: 0.24rem;
        text-align: center;
      }
      .match-content {
        width: 100%;
        padding: 0.2rem;
        .match-score {
          text-align: center;
          margin-bottom: 0.1rem;
          span {
            color: #8a8a8a;
            padding-right: 0.1rem;
          }
        }
        .match-select {
          text-align: center;
          background: #fff;
          border: 1px solid #d2d2d2;
          color: #8a8a8a;
          height: 0.54rem;
          line-height: 0.54rem;
          font-size: 0.2rem;
        }
      }
    }
  }
  .match-modal-sfc-s-pay {
    .title {
      font-size: 0.3rem;
      img {
        width: 0.28rem;
      }
      span {
        margin: 0 0.2rem;
      }
    }
    .alert {
      text-align: left;
      color: #b9b9b9;
      font-size: 0.18rem;
      margin-top: 0.2rem;
      margin-bottom: 0.1rem;
    }
    .detail {
      display: flex;
      font-size: 0.2rem;
      width: 100%;
      flex-wrap: wrap;
      .s {
        // width: 5.2rem;
        display: flex;
        width: 100%;
        .left {
          width: 0.2rem;
          padding-left: 0.05rem;
          padding-right: 0.05rem;
          display: inline-block;
          background: #c99feb;
          height: 0.9rem;
          color: #fff;
          padding-top: 0.3rem;
        }
        .right {
          display: inline-block;
          width: 100%;
          text-align: left;
          .item {
            display: inline-block;
            text-align: center;
            width: 33%;
            height: 0.5rem;
            padding-top: 0.1rem;
            background: #fbf3f4;
            &.active {
              background: #d44743;
              color: #fff;
            }
            .score {
              font-size: 0.16rem;
            }
          }
        }
      }
      .f {
        display: flex;
        width: 100%;
        .left {
          width: 0.2rem;
          padding-left: 0.05rem;
          padding-right: 0.05rem;
          display: inline-block;
          background: #7adf89;
          height: 0.9rem;
          color: #fff;
          padding-top: 0.3rem;
        }
        .right {
          display: inline-block;
          width: 100%;
          text-align: left;
          .item {
            display: inline-block;
            text-align: center;
            width: 33%;
            height: 0.5rem;
            padding-top: 0.1rem;
            background: #d5f6da;
            &.active {
              background: #d44743;
              color: #fff;
            }
            .score {
              font-size: 0.16rem;
            }
          }
        }
      }
    }
  }
}
</style>
